#include "For.h"
#include "IVisitor.h"

For::For(const exprTypePtr& target, const exprTypePtr& iter, const StmtTypeList& body, const suiteTypePtr& orelse, int nodeId):
    stmtType(nodeId),
    _target(target),
    _iter(iter),
    _body(body),
    _orelse(orelse)
{
}
    
For::~For()
{
    _body.clear();
}
    
Ast::AstTypes For::type() const
{
    return Ast::For;
}
    

exprTypePtr For::target()
{
    return _target;
}

void For::setTarget(const exprTypePtr& target)
{
    _target = target;
}

exprTypePtr For::iter()
{
    return _iter;
}

void For::setIter(const exprTypePtr& iter)
{
    _iter = iter;
}

StmtTypeList For::body()
{
    return _body;
}

void For::setBody(const StmtTypeList& body)
{
    _body = body;
}

suiteTypePtr For::orelse()
{
    return _orelse;
}

void For::setOrelse(const suiteTypePtr& orelse)
{
    _orelse = orelse;
}

    
QString For::toString() const
{
    return QString("For[target=%1, iter=%2, body=%3, orelse=%4]").
                arg(_target ? _target->toString():"").
                arg(_iter ? _iter->toString():"").
                arg(_body.toString()).
                arg(_orelse ? _orelse->toString():"");
}
    
void For::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitFor(node.dynamicCast<For>());
}
    
void For::traverse(IVisitor* visitor)
{
    if (_target != NULL)
        _target->accept(visitor, _target);
    if (_iter != NULL)
        _iter->accept(visitor, _iter);
    _body.traverse(visitor);
    if (_orelse != NULL)
        _orelse->accept(visitor, _orelse);
}